home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / GVECTS.ZIP / HSCREEN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.5 KB  |  142 lines

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <mem.h>
  5. #include <math.h>
  6. #include "hscreen.h"
  7.  
  8. HIDDEN_SCREEN::HIDDEN_SCREEN(HDC hdc, int width, int height)
  9. {
  10.     BMPINFO Info;
  11.  
  12.     Width = (WORD)width;
  13.     Height = (WORD)height;
  14.  
  15.     Orientation = -1;//(int)Info.bmiHeader.biHeight;
  16. // Use Top-Down for easier access to bytes
  17.  
  18.     Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  19.     Info.bmiHeader.biWidth = Width;
  20.     Info.bmiHeader.biHeight = -Height;
  21.     Info.bmiHeader.biPlanes = 1;
  22.     Info.bmiHeader.biBitCount = 8;
  23.     Info.bmiHeader.biCompression = BI_RGB;
  24.     Info.bmiHeader.biSizeImage = Width * Height;
  25.     Info.bmiHeader.biXPelsPerMeter = 0;
  26.     Info.bmiHeader.biYPelsPerMeter = 0;
  27.     Info.bmiHeader.biClrUsed = 256;
  28.     Info.bmiHeader.biClrImportant = 256;
  29.  
  30.     HiddenBMP = CreateDIBSection(hdc, (BITMAPINFO *)&Info, DIB_PAL_COLORS,
  31.                           &Surface, NULL, 0);
  32.     MainPal = CreateHalftonePalette(hdc);
  33.     HiddenDC = CreateCompatibleDC(hdc);
  34.     OldBMP = SelectObject(HiddenDC, HiddenBMP);
  35.  
  36.     GetPaletteEntries(MainPal, 0, 256, (PALETTEENTRY far *)Info.bmiColors);
  37.     for(int Counter = 0; Counter < 256; Counter++)
  38.     {
  39.         BYTE Temp = Info.bmiColors[Counter].rgbBlue;
  40.         Info.bmiColors[Counter].rgbBlue = Info.bmiColors[Counter].rgbRed;
  41.         Info.bmiColors[Counter].rgbRed = Temp;
  42.     }
  43.  
  44.     PatBlt(HiddenDC, 0, 0, width, height, WHITENESS);
  45.  
  46.     BmpInfo = Info;
  47. };
  48.  
  49. HIDDEN_SCREEN::~HIDDEN_SCREEN()
  50. {
  51.     SelectObject(HiddenDC, OldBMP);
  52.     DeleteObject(HiddenBMP);
  53.     DeleteDC(HiddenDC);
  54.     DeleteObject(MainPal);
  55. };
  56.  
  57. int HIDDEN_SCREEN::BltToScreen(HDC Screen, int x, int y)
  58. {
  59.     BitBlt(Screen, x, y, Width, Height, HiddenDC, 0, 0, SRCCOPY);
  60.     return 0;
  61. };
  62.  
  63. int HIDDEN_SCREEN::BltToScreen2(HDC Screen, int w, int h, int x, int y)
  64. {
  65.     BitBlt(Screen, x, y, w, h, HiddenDC, 0, 0, SRCCOPY);
  66.     return 0;
  67. };
  68.  
  69. int HIDDEN_SCREEN::StretchToScreen(HDC Screen, int x, int y, int w, int h)
  70. {
  71.     StretchBlt(Screen, x, y, w, h, HiddenDC, 0, 0, Width, Height - 3, SRCCOPY);
  72.     return 0;
  73. };
  74.  
  75. int HIDDEN_SCREEN::Clear()
  76. {
  77.     PatBlt(HiddenDC, 0, 0, Width, Height, BLACKNESS);
  78.     return 0;
  79. };
  80.  
  81. int HIDDEN_SCREEN::Clear(COLORREF Col)
  82. {
  83.     HBRUSH Brush, Oldbrush;
  84.  
  85.     Brush = CreateSolidBrush(Col);
  86.     Oldbrush = SelectObject(HiddenDC, Brush);
  87.     PatBlt(HiddenDC, 0, 0, Width, Height, PATCOPY);
  88.     SelectObject(HiddenDC, Oldbrush);
  89.     DeleteObject(Brush);
  90.     return 0;
  91. };
  92.  
  93. int HIDDEN_SCREEN::UseDCPal(HDC hdc)
  94. {
  95.     RGBQUAD Color[256];
  96.     int i;
  97.     BYTE Temp;
  98.     
  99.     GetSystemPaletteEntries(hdc, 0, 256, (PALETTEENTRY *)Color);
  100.     for(i = 0; i < 256; i++)
  101.     {
  102.         Temp = Color[i].rgbBlue;
  103.         Color[i].rgbBlue = Color[i].rgbRed;
  104.         Color[i].rgbRed = Temp;
  105.     }
  106.     SetDIBColorTable(HiddenDC, 0, 256, Color);
  107.     return 0;
  108. };
  109.     
  110. int HIDDEN_SCREEN::UseHalftonePalette(HDC hdc)
  111. {
  112.     HPALETTE Pal, Old;
  113.     RGBQUAD    Colors[256];
  114.  
  115.     Pal = CreateHalftonePalette(hdc);
  116.     Old = SelectPalette(hdc, Pal, FALSE);
  117.     RealizePalette(hdc);
  118.     DeleteObject(Old);
  119.  
  120.     GetPaletteEntries(Pal, 0, 256, (PALETTEENTRY far *)Colors);
  121.     for(int i = 0; i < 256; i++)
  122.     {
  123.         BYTE Temp = Colors[i].rgbBlue;
  124.         Colors[i].rgbBlue = Colors[i].rgbRed;
  125.         Colors[i].rgbRed = Temp;
  126.     }
  127.     SetDIBColorTable(HiddenDC, 0, 256, Colors);
  128.     return 0;
  129. };
  130.  
  131. void AdjustClientRegion(HWND hWindow, int x1, int y1, int w, int h)
  132. {
  133.     RECT r;
  134.     long NewWidth, NewHeight;
  135.  
  136.     GetClientRect(hWindow, &r);
  137.     NewWidth = w - (r.right - r.left);
  138.     NewHeight = h - (r.bottom - r.top);
  139.     GetWindowRect(hWindow, &r);
  140.     SetWindowPos(hWindow, HWND_TOP, 0, 0, r.right - r.left + NewWidth, r.bottom - r.top + NewHeight, SWP_NOZORDER);
  141. };
  142.